class Utils {
    constructor() {
        this.dict = {
            "string": "[object String]",
            "object": "[object Object]",
            "array": "",
        }
    }

    is2type(value, type = "string") {
        return Object.prototype.toString.call(value) === this.dict[type];
    }
}

const defineReactive = (data) => {
    const utils = new Utils();
    if (utils.is2type(data, "object")) {
        for (const props of Object.keys(data)) {
            const value = data[props];
            Object.defineProperty(data, props, {
                enumerable: true,
                configurable: true,
                set(newVal) {
                    if (value != newVal) value = newVal;
                },
                get() {
                    console.log(value);
                    return value;
                }
            });
            defineReactive(value);
        }
    }
}

module.exports = {
    Utils,
    defineReactive
}

